"""
回归
"""
import numpy as np
from sklearn import metrics as me

# 跳过第一行读取数据集全部内容
file = '.\Regression.csv'
with open(file) as f:
    target = np.loadtxt(file, dtype=float, delimiter=",", skiprows=1, usecols=1)
    pre1 = np.loadtxt(file, dtype=float, delimiter=",", skiprows=1, usecols=2)
    pre2 = np.loadtxt(file, dtype=float, delimiter=",", skiprows=1, usecols=3)
    pre3 = np.loadtxt(file, dtype=float, delimiter=",", skiprows=1, usecols=4)


# MSE--相当于target-pre的二范数的平方/n
def mse(tar, pre):
    return np.linalg.norm(tar - pre, ord=2) ** 2 / len(tar)


# RMSE--相当于target-pre的二范数/根号n
def rmse(tar, pre):
    return np.linalg.norm(tar - pre, ord=2) / np.sqrt(len(tar))


# MAE--相当于target-pre的一范数/n
def mae(tar, pre):
    return np.linalg.norm(tar - pre, ord=1) / len(tar)


print("MSE: ", "pre1:", mse(target, pre1), "pre2:", mse(target, pre2), "pre3:", mse(target, pre3))
print("RMSE:", "pre1:", rmse(target, pre1), "pre2:", rmse(target, pre2), "pre3:", rmse(target, pre3))
print("MAE: ", "pre1:", mae(target, pre1), "pre2:", mae(target, pre2), "pre3:", mae(target, pre3))

"""
# 调用sklearn.metrics库验证
print("pre1", "MSE", me.mean_squared_error(target, pre1), 
      "RMSE", me.mean_squared_error(target, pre1) ** 0.5,
      "MAE", me.mean_absolute_error(target, pre1))
"""
